package com.example.text.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.text.dao.AdminRoleMenuDao;
import com.example.text.entity.AdminRoleMenu;
import com.example.text.entity.User;
import com.example.text.service.AdminRoleMenuService;
import com.example.text.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class AdminRoleMenuServiceImpl extends ServiceImpl<AdminRoleMenuDao, AdminRoleMenu> implements AdminRoleMenuService {

    @Autowired
    AdminRoleMenuDao adminRoleMenuDao;

    public List<AdminRoleMenu> findAllByRid(int rid) {
        return adminRoleMenuDao.selectList(new QueryWrapper<AdminRoleMenu>().eq("rid", rid));
    }

    public List<AdminRoleMenu> findAllByRid(List<Integer> rids) {
        return adminRoleMenuDao.findAllListByRids(rids);
    }

    @Transactional
    public void updateRoleMenu(int rid, Map<String,List<Integer>> menusIds) {
        System.out.println("前端传的menusIds值为"+menusIds);
        System.out.println("前端传的rid值为"+rid);
        adminRoleMenuDao.delete(new QueryWrapper<AdminRoleMenu>().eq("rid",rid));

        for (Integer mid : menusIds.get("menusIds")) {
            AdminRoleMenu rm = new AdminRoleMenu();
            rm.setMid(mid);
            rm.setRid(rid);
            adminRoleMenuDao.insert(rm);
        }


    }

}
